package com.zlt.bkparking.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zlt.bkparking.dto.AppUserDTO;
import com.zlt.bkparking.dto.FeedBackDTO;
import com.zlt.bkparking.entity.*;
import com.zlt.bkparking.mapper.AppUserMapper;
import com.zlt.bkparking.mapper.FeedbackMapper;
import com.zlt.bkparking.mapper.ParkingLotMapper;
import com.zlt.bkparking.mapper.ParkingOrderMapper;
import com.zlt.bkparking.service.FeedBackService;
import com.zlt.bkparking.utils.StringUtil;
import com.zlt.bkparking.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class FeedBackServiceImpl implements FeedBackService {

    @Autowired
    private FeedbackMapper feedbackMapper;



    @Override
    public PageInfo<FeedbackVO> selectFeedBackByplId(FeedBackDTO feedBackDTO) {
        /*传入参数为空 默认查找10条数据*/
        /*传入参数为空 默认查找10条数据*/
        feedBackDTO.setPage(feedBackDTO.getPage()==null?1:feedBackDTO.getPage());
        feedBackDTO.setLimit(feedBackDTO.getLimit()==null?10:feedBackDTO.getLimit());
        /*开启分页插件*/
        PageHelper.startPage(feedBackDTO.getPage(),feedBackDTO.getLimit());
        List<Feedback> feedbackList = feedbackMapper.selectFeedBackByplId(feedBackDTO.getPlId());
        PageInfo<FeedbackVO> pageInfo=new PageInfo(feedbackList);
        List<FeedbackVO> data = new ArrayList<>();
        pageInfo.setList(data);
        feedbackList.forEach(f ->{
            FeedbackVO FeedbackVO = new FeedbackVO();
            BeanUtils.copyProperties(f,FeedbackVO);
            data.add(FeedbackVO);
        });
        System.out.println(pageInfo);
        return pageInfo;
    }

    @Override
    public PageInfo<FeedbackVO> selectFeedBackByauId(FeedBackDTO feedBackDTO) {
        /*传入参数为空 默认查找10条数据*/
        /*传入参数为空 默认查找10条数据*/
        feedBackDTO.setPage(feedBackDTO.getPage()==null?1:feedBackDTO.getPage());
        feedBackDTO.setLimit(feedBackDTO.getLimit()==null?10:feedBackDTO.getLimit());
        /*开启分页插件*/
        PageHelper.startPage(feedBackDTO.getPage(),feedBackDTO.getLimit());
        List<Feedback> feedbackList = feedbackMapper.selectFeedBackByauId(feedBackDTO.getAuId());
        PageInfo<FeedbackVO> pageInfo=new PageInfo(feedbackList);
        List<FeedbackVO> data = new ArrayList<>();
        pageInfo.setList(data);
        feedbackList.forEach(f ->{
            FeedbackVO FeedbackVO = new FeedbackVO();
            BeanUtils.copyProperties(f,FeedbackVO);
            data.add(FeedbackVO);
        });
        System.out.println(pageInfo);
        return pageInfo;
    }

    @Override
    public PageInfo<FeedbackVO> selectFeedBackByfbTime(FeedBackDTO feedBackDTO) {
        /*传入参数为空 默认查找10条数据*/
        /*传入参数为空 默认查找10条数据*/
        feedBackDTO.setPage(feedBackDTO.getPage()==null?1:feedBackDTO.getPage());
        feedBackDTO.setLimit(feedBackDTO.getLimit()==null?10:feedBackDTO.getLimit());
        /*开启分页插件*/
        PageHelper.startPage(feedBackDTO.getPage(),feedBackDTO.getLimit());
        List<Feedback> feedbackList = feedbackMapper.selectFeedBackByfbTime(feedBackDTO.getFbTime());
        PageInfo<FeedbackVO> pageInfo=new PageInfo(feedbackList);
        List<FeedbackVO> data = new ArrayList<>();
        pageInfo.setList(data);
        feedbackList.forEach(f ->{
            FeedbackVO FeedbackVO = new FeedbackVO();
            BeanUtils.copyProperties(f,FeedbackVO);
            data.add(FeedbackVO);
        });
        System.out.println(pageInfo);
        return pageInfo;
    }



    @Override
    public PageInfo<FeedbackVO> selectFeed(FeedBackDTO feedBackDTO) {
        /*传入参数为空 默认查找10条数据*/
        /*传入参数为空 默认查找10条数据*/
        feedBackDTO.setPage(feedBackDTO.getPage()==null?1:feedBackDTO.getPage());
        feedBackDTO.setLimit(feedBackDTO.getLimit()==null?10:feedBackDTO.getLimit());
        /*开启分页插件*/
        PageHelper.startPage(feedBackDTO.getPage(),feedBackDTO.getLimit());
        FeedbackExample feedbackexample = new FeedbackExample();
        List<Feedback> feedbackList = feedbackMapper.selectByExample(feedbackexample);
        PageInfo<FeedbackVO> pageInfo=new PageInfo(feedbackList);
        List<FeedbackVO> data = new ArrayList<>();
        pageInfo.setList(data);
        feedbackList.forEach(f ->{
            FeedbackVO FeedbackVO = new FeedbackVO();
            BeanUtils.copyProperties(f,FeedbackVO);
            data.add(FeedbackVO);
        });
        System.out.println(pageInfo);
        return pageInfo;
    }

    @Override
    public boolean updatestate(FeedBackDTO feedBackDTO) {

        Feedback feedback = new Feedback();
        BeanUtils.copyProperties(feedBackDTO,feedback);
        int updatestate = feedbackMapper.updateByPrimaryKeySelective(feedback);

        return updatestate>0;
    }

    @Override
    public boolean delfeedback(Long fbId) {
        Boolean delfeedback = feedbackMapper.delfeedback(fbId);
        return delfeedback;
    }

    @Override
    public PageInfo<FeedbackVO> selectUnread(FeedBackDTO feedBackDTO) {
        /*传入参数为空 默认查找10条数据*/
        /*传入参数为空 默认查找10条数据*/
        feedBackDTO.setPage(feedBackDTO.getPage()==null?1:feedBackDTO.getPage());
        feedBackDTO.setLimit(feedBackDTO.getLimit()==null?10:feedBackDTO.getLimit());
        /*开启分页插件*/
        PageHelper.startPage(feedBackDTO.getPage(),feedBackDTO.getLimit());
        List<Feedback> feedbackList = feedbackMapper.selectState(false);
        PageInfo<FeedbackVO> pageInfo=new PageInfo(feedbackList);
        List<FeedbackVO> data = new ArrayList<>();
        pageInfo.setList(data);
        feedbackList.forEach(f ->{
            FeedbackVO FeedbackVO = new FeedbackVO();
            BeanUtils.copyProperties(f,FeedbackVO);
            data.add(FeedbackVO);
        });
        System.out.println(pageInfo);
        return pageInfo;
    }

    @Override
    public PageInfo<FeedbackVO> selectRead(FeedBackDTO feedBackDTO) {
        /*传入参数为空 默认查找10条数据*/
        /*传入参数为空 默认查找10条数据*/
        feedBackDTO.setPage(feedBackDTO.getPage()==null?1:feedBackDTO.getPage());
        feedBackDTO.setLimit(feedBackDTO.getLimit()==null?10:feedBackDTO.getLimit());
        /*开启分页插件*/
        PageHelper.startPage(feedBackDTO.getPage(),feedBackDTO.getLimit());
        List<Feedback> feedbackList = feedbackMapper.selectState(true);
        PageInfo<FeedbackVO> pageInfo=new PageInfo(feedbackList);
        List<FeedbackVO> data = new ArrayList<>();
        pageInfo.setList(data);
        feedbackList.forEach(f ->{
            FeedbackVO FeedbackVO = new FeedbackVO();
            BeanUtils.copyProperties(f,FeedbackVO);
            data.add(FeedbackVO);
        });
        System.out.println(pageInfo);
        return pageInfo;
    }


}
